package com.yiya.ms.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yiya.bean.News;
import com.yiya.ms.annotation.Auth;
import com.yiya.service.NewsService;

@Controller
@RequestMapping("/welcome")
public class WelcomeAction extends BaseAction{
	@SuppressWarnings("unused")
	private final static Logger log= Logger.getLogger(WelcomeAction.class);

	@Autowired
	private NewsService newsService;
	
	@Auth(verifyLogin=false,verifyURL=false)
	@RequestMapping("") 
	public String list(HttpServletRequest request,Model model){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("category", 1);
		List<News> education = newsService.getIndexNews(param);//各地教育
		param.put("category", 2);
		List<News> society = newsService.getIndexNews(param);//社会民生
		param.put("category", 3);
		List<News> recreation = newsService.getIndexNews(param);//娱乐快讯
		param.put("category", 4);
		List<News> military = newsService.getIndexNews(param);//军情聚焦
		model.addAttribute("education", education);
		model.addAttribute("society", society);
		model.addAttribute("recreation", recreation);
		model.addAttribute("military", military);
		Map<String,Object>  context = getRootMap();
		model.addAttribute("context", context);
		return "index";
	}
	
	@Auth(verifyLogin=false,verifyURL=false)
	@RequestMapping("/newsDetail/{id}")
	public String newsDetail(@PathVariable("id")int id,HttpServletRequest request,Model model){
		News news = newsService.queryById(id);
		model.addAttribute("news", news);
		Map<String,Object>  context = getRootMap();
		model.addAttribute("context", context);
		return "news/news_detail";
	}
}
